package SellerAgent;

import Ontologies.TreeWithPrice;

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: jiaka_000
 * Date: 13-5-18
 * table model used to show selling list in JTable
 */
public class SellingListTableModel extends AbstractTableModel {
    private List<List<Object>> data = new ArrayList<List<Object>>();
    private List<String> columnNames = new ArrayList<String>();

    public SellingListTableModel(List<TreeWithPrice> sellingList) {
        super();
        columnNames.add("Common Name");
        columnNames.add("Latin Name");
        columnNames.add("Category");
        columnNames.add("Unit Price");
        columnNames.add("Quantity");

        for (TreeWithPrice tree:sellingList) {
            addRow(tree);
        }
    }

    @Override
    public int getColumnCount() {
        return columnNames.size();
    }

    @Override
    public String getColumnName(int column) {
        return columnNames.get(column);
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return data.get(rowIndex).get(columnIndex);
    }

    public void removeRow(int row) {
        data.remove(row);
    }

    public void addRow(TreeWithPrice tree) {
        List<Object> tmp = new ArrayList<Object>();
        tmp.add(tree.getCommonName());
        tmp.add(tree.getLatinName());
        tmp.add(tree.getCategory());
        tmp.add(tree.getUnitPrice());
        tmp.add(tree.getQuantity());
        data.add(tmp);
    }
}
